<?php
namespace app\lib\exception;


use think\exception\Handle;
use Exception;
class ExceptionHandler extends Handle
{
    public $code;
    public $msg;
    public $errorCode;

    public function render(Exception $e)
    {
        if($e instanceof BaseException){
            $this->code = $e->code;
            $this->msg = $e->msg;
            $this->errorCode = $e->errorCode;
        }else{
            //bug开启显示默认异常
            if(config('app_debug')) return parent::render($e);
            $this->code = 500;
            $this->msg = '服务器异常';
            $this->errorCode = 999;
        }
        $res = [
            'errorCode' => $this->errorCode,
            'msg' => $this->msg
        ];

        return json($res,$this->code);
    }
}